package com.xiaodou.mjf.application.core.service.impl;

import java.util.List;

import javax.annotation.Resource;
import javax.persistence.criteria.Predicate;
import javax.transaction.Transactional;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;

import com.xiaodou.mjf.application.core.repository.NotesBookRepository;
import com.xiaodou.mjf.application.core.service.NotesBookService;
import com.xiaodou.mjf.entity.core.NotesBook;
import com.xiaodou.mjf.infrastructure.common.app.JpaSimpleService;


/***
 *
 * NotesBook业务访问实现
 * @author XiaoDou.com Code Generator
 * @version 1.0
 * 2014-10-29 17:37:52
 *
 */
@Service("notesBookServiceForJPA") @Transactional
public class NotesBookServiceImpl extends JpaSimpleService<NotesBook,String> implements NotesBookService{

	Logger logger = LoggerFactory.getLogger(NotesBookServiceImpl.class);

    @Resource
    NotesBookRepository notesBookRepository;

    @Override
    protected JpaRepository<NotesBook, String> getRepository() {
        return notesBookRepository;
    }
    
    @Override
    public Page<NotesBook> page(NotesBook entity) {
    

    	return notesBookRepository.findAll((root,query,cb) -> {
    		
    		Predicate p1 = cb.equal(root.get("status").as(Integer.class),NotesBook.NORMAL);
    		Predicate p2 = cb.equal(root.get("account").as(String.class),entity.getAccount());
    		
    		return query.where(p1,p2).getRestriction();
    		
    	},preparePage(entity,new Sort(Direction.DESC,"txnDate")));
    	
    }
    @Override
    public List<NotesBook> transactionFlow(String memberId){
    	return notesBookRepository.transactionFlow(memberId);
    			
    }
}

